package com.company.structural.composite_pattern.composite;

import com.company.structural.composite_pattern.component.AbstractFile;

import java.util.ArrayList;

/**
 * @ClassName Folder
 * @Author tiezheng.han
 * @Date 2020/8/31 15:03
 **/
public class Folder extends AbstractFile {

    /**
     * 定义集合fileList,用于存储abstractFile类型的成员
     */
    private ArrayList<AbstractFile> fileList = new ArrayList<AbstractFile>();

    private String name;

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile file) {
        fileList.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        fileList.remove(file);
    }

    @Override
    public AbstractFile getChild(int i) {
        return fileList.get(i);
    }

    @Override
    public void killVirust() {
        //模拟杀毒软件
        System.out.println(" * * * 对文件夹‘" + name + "’进行杀毒");
        System.out.println(fileList.toString());
        for (AbstractFile file : fileList){
            file.killVirust();
        }
    }

    @Override
    public String toString() {
        return "Folder{" +
                "fileList=" + fileList +
                ", name='" + name + '\'' +
                '}';
    }
}
